<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	/* 重置浏览器默认样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    background-color: #f5f5f5;
    color: #333;
    padding: 20px;
}

/* 容器样式，用于居中表格 */
.container {
    width: 90%;
    max-width: 1200px; /* 根据需要调整最大宽度 */
    margin: 0 auto; /* 水平居中 */
    overflow: hidden; /* 清除浮动 */
}

/* 表格样式 */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table th,
.table td {
    text-align: center;
    padding: 15px;
    border: 1px solid #e1e1e1;
}

.table th {
    background-color: #5cb85c;
    color: #fff;
}

.table td {
    height: 50px;
}

/* 条纹效果 */
.table tr:nth-child(odd) {
    background-color: #f9f9f9;
}

/* 按钮样式 */
.btn {
    padding: 8px 20px;
    margin: 4px;
    border: none;
    border-radius: 5px;
    color: #fff;
    background-color: #337ab7;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.btn:hover {
    background-color: #286090;
}

/* 链接样式 */
.link {
    text-decoration: none;
    color: #337ab7;
    transition: color 0.3s ease;
    padding: 10px;
}

.link:hover {
    color: #23527c;
    text-decoration: underline;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        width: 100%;
        padding: 0 20px;
    }

    .table thead {
        display: none; /* 隐藏表头 */
    }

    .table, .table tbody, .table tr, .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        margin-bottom: 10px;
    }

    .table td {
        text-align: right;
        padding-left: 50%;
        text-align: right;
        position: relative;
    }

    .table td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 50%;
        padding-left: 15px;
        font-weight: bold;
        text-align: left;
    }
}

</style>
</head>
<body>
<div class="container">
	<table  class="table">
		<tr style="text-align:center;height:50px">
			<td style="width:200px">类别编号</td>
			<td style="width:200px">类别名称</td>
			<td style="width:200px">操作</td>		
		</tr>
		<c:forEach items="${categoryList }" var="category">
		<tr>
			<td>${category.category }</td>
			<td>${category.categoryName }</td>
			<c:if test="${category.category<=6 }">
			<td>默认分类，不可操作</td>
			</c:if>
			<c:if test="${category.category>6 }">
			<td><input type="button" value="修改" onclick="edit(${category.category })" class="btn">&nbsp;&nbsp;&nbsp;<input type="button" value="删除" id="delete" onclick="del(${category.category })" class="btn"></td>
			</c:if>
		</tr>
		</c:forEach>
		<tr>
			<td colspan="3"><a href="admin_addCategory.jsp" class="link">添加</a>&nbsp;&nbsp;&nbsp;<a href="adminIndex.jsp" class="link">返回</a></td>
		</tr>	
	</table>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/layer/layer.js"></script>
<script type="text/javascript">
	function edit(categoryId){
		window.location.href="AdminUpdateCategoryServlet?categoryId="+categoryId;
	}
	function del(categoryId) {
	    $.post("AdminDeleteCategoryServlet", {
	        categoryId: categoryId
	    }, function(data) {
	        if (data === "OK") { // 使用 === 进行严格比较
	            layer.msg("删除成功");
	            var timer = setTimeout(move, 2000); // 保存 setTimeout 返回的 ID
	        } else {
	            layer.msg("删除失败");
	        }
	    });
	}
	function move(){
		window.location.href="AdminCategoryServlet2";
	}
</script>
</body>
</html>